<template>
  <a-card :bordered="false">
    <!--  #####################查询条件###################  -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="8" :sm="24">
            <a-form-item label="服务商名称">
              <a-input v-model="queryParam.name" placeholder=""/>
            </a-form-item>
          </a-col>
          <a-col :md="!advanced && 8 || 24" :sm="24">
            <span class="table-page-search-submitButtons" :style="advanced && { float: 'right', overflow: 'hidden' } || {} ">
              <a-button v-action:query type="primary" @click="$refs.table.refresh(true)">查询</a-button>
              <a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!--  #####################查询条件###################  -->

    <!--  #####################操作###################  -->
    <div class="table-operator">
      <a-button v-action:add type="primary" icon="plus" @click="handleEdit('null')">新建</a-button>
    </div>
    <!--  #####################操作###################  -->

    <!--  #####################表格###################  -->
    <s-table
      ref="table"
      :columns="columns"
      :data="loadData"
      bordered
    >

      <span slot="action" slot-scope="text, record">
        <template>
          <a v-action:edit @click="handleEdit(record)">编辑</a>
          <a-divider v-action:edit type="vertical" />
          <a v-action:delete @click="handleDel(record)">删除</a>
        </template>
      </span>
    </s-table>
    <!--  #####################表格###################  -->
  </a-card>
</template>

<script>
import moment from 'moment'
import { STable } from '@/components'
import { selectPage, del } from '@/api/system/company'

export default {
  components: {
    STable
  },
  data () {
    return {
      mdl: {},
      // 高级搜索 展开/关闭
      advanced: false,
      // 查询参数
      queryParam: {},
      // 表头
      columns: [
        {
          title: '服务商名称',
          dataIndex: 'name'
        },
        {
          title: '部门编号',
          dataIndex: 'code'
        },
        {
          title: '服务商公众号appid',
          dataIndex: 'wxAppId'
        },{
          title: '微信商户号',
          dataIndex: 'wxMchId'
        },
        {
          title: '支付宝应用ID',
          dataIndex: 'aliAppId'
        },
        {
          title: '操作',
          dataIndex: 'action',
          width: '150px',
          scopedSlots: { customRender: 'action' }
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        //查询服务商
        this.queryParam.type = 1
        return selectPage(Object.assign(parameter, this.queryParam))
          .then(res => {
            return res.result
          })
      }
    }
  },
  filters: {
  },
  methods: {
    handleEdit (record) {
      this.$emit('onEdit', record)
    },
    handleDel (record) {
      const _this = this
      this.$confirm({
        title: '警告',
        content: `真的要删除 ${record.name} 吗?`,
        okText: '删除',
        okType: 'danger',
        cancelText: '取消',
        onOk() {
          // 在这里调用删除接口
          del(record.id).then(res => {
            if (res.code === 200) {
              _this.$message.success(res.message)
              _this.$refs.table.refresh()
            }
          })
        }
      })
    },
  }
}
</script>
